<?php
session_start();

$key = $_GET['key'];
$val = $_GET['val'];

include 'dbconnect.php';

$id = $_SESSION['wid'];

  // Check connection
if (mysqli_connect_errno())
  {
  //echo "alert'Failed to connect to MySQL: ' . mysqli_connect_error()";
  }

$result = mysqli_query($con,"SELECT * FROM connections");

$error = 0;

while($row = mysqli_fetch_array($result))
  {
  if ($row['id']==$id){
    
	$sql="UPDATE `connections` SET `$key` = '$val';";

     if (!mysqli_query($con,$sql))
     {
          echo('Error: ' . mysqli_error($con));
     }
if(isset($_SESSION['email']))
  unset($_SESSION['email']);
if(isset($_SESSION['display']))
  unset($_SESSION['display']); 
    $_SESSION['email']=$row['email'];
    $_SESSION['display']=$row['displayName'];
    break;
  }
  }
mysqli_close($con);
?>
